package com.nanyang.tms.controller.pick;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.pick.*;
import com.nanyang.tms.api.dto.response.pick.CompanyPickGoodsPageResponse;
import com.nanyang.tms.api.dto.response.pick.PickGoodsPageResponse;
import com.nanyang.tms.api.service.pick.PickGoodsRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/pick")
public class PickGoodsController {


    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private PickGoodsRpcService pickGoodsRpcService;

    /**
     * <p>listPickGoods</p>
     * <p>Description:查询表</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResult<PageBean<PickGoodsPageResponse>> listPickGoods(@RequestBody PickGoodsQueryRequest param) {
        ApiResult<PageBean<PickGoodsPageResponse>> apiResult = pickGoodsRpcService.listPickGoods(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 修改司机
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/updateDriver", method = RequestMethod.POST)
    public ApiResult<Boolean> updateDriver(@BindParam @RequestBody @Valid PickGoodsDriverRequest param) {
        ApiResult<Boolean> apiResult = pickGoodsRpcService.updateDriver(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     *分配司机
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/driverState", method = RequestMethod.POST)
    public ApiResult<Boolean> driverState(  @BindParam @RequestBody @Valid PickGoodsDriverRequest param) {
        ApiResult<Boolean> apiResult = pickGoodsRpcService.driverState(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 前台-取消
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/cancelState", method = RequestMethod.POST)
    public ApiResult<Boolean> cancelState(  @BindParam @RequestBody @Valid PickGoodsUpdateStateRequest param) {
        ApiResult<Boolean> apiResult = pickGoodsRpcService.cancelState(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 前台-已取货
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/alreadyState", method = RequestMethod.POST)
    public ApiResult<Boolean> alreadyState(  @BindParam @RequestBody @Valid PickGoodsUpdateStateRequest param) {
        ApiResult<Boolean> apiResult = pickGoodsRpcService.alreadyState(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 前台-添加提货
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ApiResult<Boolean> savePickGoods(  @BindParam @RequestBody @Valid PickGoodsAddRequest param) {
        ApiResult<Boolean> apiResult = pickGoodsRpcService.savePickGoods(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 前台-列表提货
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/listCompany", method = RequestMethod.POST)
    public ApiResult<PageBean<CompanyPickGoodsPageResponse>> listPickGoods( @BindParam @RequestBody CompanyPickGoodsQueryRequest param) {
        ApiResult<PageBean<CompanyPickGoodsPageResponse>> apiResult = pickGoodsRpcService.listCompanyPickGoods(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

}
